package dk.mirasola.systemtraining.server.entity;

import com.google.appengine.api.datastore.Email;
import com.google.appengine.api.users.User;
import com.googlecode.objectify.annotation.Unindexed;
import dk.mirasola.systemtraining.bridgewidgets.shared.model.Seat;
import dk.mirasola.systemtraining.bridgewidgets.shared.model.distributionfiltertree.DistributionFilterGroup;
import dk.mirasola.systemtraining.server.DistributionFilterGroupFactory;

import javax.persistence.Id;
import javax.persistence.PostLoad;
import javax.persistence.PrePersist;
import javax.persistence.Transient;
import java.util.Date;

public class BiddingSet {
    public static enum State {
        INITIALISED, BIDDING_IN_PROGRESS, COMPLETED
    }

    @Id
    Long id;

    User owner;

    String name;

    @Unindexed
    String description;

    State state;

    @Unindexed
    String distributionFilterGroupStr;

    @Transient
    DistributionFilterGroup distributionFilterGroup;

    @Unindexed
    int boardsCount;

    @Unindexed
    Seat seatInTurn;

    @Unindexed
    Email northEmail;

    @Unindexed
    String northLocale;

    @Unindexed
    Email southEmail;

    @Unindexed
    String southLocale;

    Date created;

    public BiddingSet() {
    }

    public Long getId() {
        return id;
    }

    public User getOwner() {
        return owner;
    }

    public void setOwner(User owner) {
        this.owner = owner;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public State getState() {
        return state;
    }

    public void setState(State state) {
        this.state = state;
    }

    public DistributionFilterGroup getDistributionFilterGroup() {
        return distributionFilterGroup;
    }

    public void setDistributionFilterGroup(DistributionFilterGroup distributionFilterGroup) {
        this.distributionFilterGroup = distributionFilterGroup;
    }

    public int getBoardsCount() {
        return boardsCount;
    }

    public void setBoardsCount(int boardsCount) {
        this.boardsCount = boardsCount;
    }

    public Seat getSeatInTurn() {
        return seatInTurn;
    }

    public void setSeatInTurn(Seat seatInTurn) {
        this.seatInTurn = seatInTurn;
    }

    public Email getNorthEmail() {
        return northEmail;
    }

    public void setNorthEmail(Email northEmail) {
        this.northEmail = northEmail;
    }

    public String getNorthLocale() {
        return northLocale;
    }

    public void setNorthLocale(String northLocale) {
        this.northLocale = northLocale;
    }

    public Email getSouthEmail() {
        return southEmail;
    }

    public void setSouthEmail(Email southEmail) {
        this.southEmail = southEmail;
    }

    public String getSouthLocale() {
        return southLocale;
    }

    public void setSouthLocale(String southLocale) {
        this.southLocale = southLocale;
    }

    public Date getCreated() {
        return created;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    @PrePersist
    void distributionFilterGroupToString() {
        distributionFilterGroupStr = DistributionFilterGroupFactory.distributionFilterGroupToString(distributionFilterGroup);
    }

    @PostLoad
    void stringToDistributionFilterGroup() {
        distributionFilterGroup = DistributionFilterGroupFactory.stringToDistributionFilterGroup(distributionFilterGroupStr);
    }

}
